import { createStore } from "vuex";
import bian from "@/store/store-modules/bian";
import li from "@/store/store-modules/li";
import zhai from "@/store/store-modules/zhai";
import duan from "@/store/store-modules/duan";
import yan from "@/store/store-modules/yan";

export default createStore({
  state: {
    user: {
      userName: "",
      headImg: "",
    },
    token: localStorage.getItem("token") || "",
  },
  mutations: {
    setToken(state, a) {
      if (a) {
        localStorage.setItem("token", a);
      } else {
        localStorage.removeItem("token");
      }
      state.token = a;
    },
    setUser(state, a) {
      state.user = a;
    },
  },
  actions: {},
  modules: {
    bian,
    li,
    zhai,
    duan,
    yan,
  },
});
